package Demo_01;

import java.util.concurrent.TimeUnit;

public class Demo_waitNotify {
    public static void main(String[] args) {
        //创建一个锁对象
        Object locker = new Object();
        //线程1   演示wait（）方法
        Thread t1 = new Thread(() -> {
            while (true) {
                System.out.println("wait启动前...");
                synchronized (locker) {
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("wait唤醒后...");
                    System.out.println("==================");
                }
            }
        });
        Thread t2 = new Thread(() -> {
            while (true) {
                System.out.println("唤醒之前...");
                synchronized (locker) {
                    locker.notifyAll();
                }
                System.out.println("唤醒之后...");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        //启动线程
        t1.start();
        t2.start();
    }
}
